﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.ElasticSearch;
using Abp.EntityFrameworkCore.Repositories;
using Abp.Json;
using AbpBuild;
using AbpBuild.Authorization.Users;
using AbpBuild.Configuration;
using AbpBuild.LawManage;
using AbpBuild.LawManage.Dto;
using AbpBuild.WenShu;
using Castle.Core.Internal;
using DotnetSpider.Selector;
using HtmlAgilityPack;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Nest;
using Newtonsoft.Json.Linq;

namespace MultipleDbContextEfCoreDemo.Services
{
    public class LawAppService : AbpBuildAppServiceBase, ILawAppService
    {
        private readonly IRepository<LawRecord, string> _lawrecordrepository; //in the first db
        private readonly IRepository<LawRecordOther, int> _lawrecordotherrepository; //in the first db
        private AbpElasticSearch _abpElasticSearch;
        private BaseDatasHelper _baseDatasHelper;
        private static IConfigurationRoot _appConfiguration = AppConfigurations.Get(System.Environment.CurrentDirectory);
        readonly IUnitOfWorkManager _unitOfWorkManager;


        public LawAppService(
            IRepository<LawRecord, string> lawrecordrepository,
            IRepository<LawRecordOther, int> lawrecordotherrepository,
            BaseDatasHelper baseDatasHelper,
            AbpElasticSearch abpElasticSearch,
            IUnitOfWorkManager unitOfWorkManager
        )
        {
            _lawrecordrepository = lawrecordrepository;
            _lawrecordotherrepository = lawrecordotherrepository;
            _abpElasticSearch = abpElasticSearch;
            _baseDatasHelper = baseDatasHelper;
            _unitOfWorkManager = unitOfWorkManager;
        }

        public string GetFenIk_smart(string text)
        {
            //"蓝瘦香菇  SSMS 的 SelectTopNRows 命令的脚 本 在这里输入你要搜索的内容脚本雅虎 猫扑中山国际网.flac".
            var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Analyzer("ik_smart").Text(text).Pretty());
            //var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Analyzer("ik_max_word").Text(text, text, text).Pretty());
           // var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Text(text).Pretty());
            return s.Tokens.ToJsonString();
        }
        public string GetFenIk_max_word(string text)
        {
            //"蓝瘦香菇  SSMS 的 SelectTopNRows 命令的脚 本 在这里输入你要搜索的内容脚本雅虎 猫扑中山国际网.flac".
            //var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Analyzer("ik_smart").Text(text).Pretty());
            var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Analyzer("ik_max_word").Text(text).Pretty());
            // var s = _abpElasticSearch.EsClient.Indices.Analyze(x => x.Text(text).Pretty());
            return s.Tokens.ToJsonString();
        }
        public async Task LawCrateIndexAsync()
        {
            await _abpElasticSearch.CreateIndexAsync<LawInputDTO, string>("law");
        }
        public async Task LawDetailCrateIndexAsync()
        {
            await _abpElasticSearch.CreateIndexAsync<LawInputDetailDTO, string>("lawdetail");
        }
        public async Task ReIndex(string name)
        {
            await _abpElasticSearch.ReIndex<LawInputDTO, string>(name);
        }
        public async Task DelIndex(string name)
        {
            await _abpElasticSearch.DeleteIndexAsync(name);
        }

        [UnitOfWork(System.Transactions.IsolationLevel.ReadUncommitted)]
        public void LawAddorUpdate()
        {
            int taltal = 0;
            int srows = 0;
            int srowtotl = 0;
            int indexed = 0;
            string cccc = string.Empty;
            string idssss = string.Empty;
            int indexNum = Convert.ToInt32(_appConfiguration.GetConnectionString("indexNum"));
            string emm = "　"; 
            while (true)
            {
                try
                {
                    using (var uowHandle = _unitOfWorkManager.Begin())
                    {
                        //ABGH
                        //string LawTpyeABGH = _appConfiguration.GetConnectionString("LawTpyeABGH");
                        ///http://www.faxin.cn/lib/zyfl/ZyflContent.aspx?gid=A37236&libid=all      A290592
                        ///http://www.faxin.cn/lib/dffl/dfflcontent.aspx?gid=B105813&libid=010202
                        ///http://www.faxin.cn/lib/lfsf/LfContent.aspx?gid=G8026&libid=010301
                        ///http://www.faxin.cn/lib/lfsf/SfContent.aspx?gid=H7024&libid=010401

                        if (taltal == 0)
                        {
                            //taltal = _lawrecordrepository.GetAll().Where(p => p.Indexed != indexNum || p.Indexed == null).Count();
                        }

                        List<LawRecord> lawrecords = new List<LawRecord>();


                        //LawRecord lawrecord = _lawrecordrepository.Get("A296659");
                        //lawrecords.Add(lawrecord);
                        int timeu = 0;
                        while (lawrecords.Count == 0)
                        {
                            try
                            {
                                timeu = 0;
                                lawrecords = _lawrecordrepository.GetAll().Where(p => (p.Indexed != indexNum && p.Indexed != 9999) || p.Indexed == null).Take(1).ToList();
                            }
                            catch (Exception ex)
                            {
                            }
                            if (lawrecords.Count == 0)
                            {
                                timeu += 1;
                                Console.WriteLine("获取不到数据!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + timeu.ToString());
                                Thread.Sleep(1000 * 60);
                            }
                        }

                        //update [dbo].[LawRecord] set Indexed = 1 where id in ('A11112','B741528','A289846','B735172')B742903   B744022  B248094 A203254  B372931  A1529  A16146  A195396 A212849  A199333  A209561 A363  A337
                        //A215701  A215922  A211067  A6331  A214482  A13044  B700770  A12170  A7471  A7610  A7730  A7791  A10823 A214860 A17331 A17382  A20677 A21032  A23330 A3029 A5978  A7042 B770789  A35922 A44522 A57775 
                        //A62918 A37236



                        srowtotl += lawrecords.Count;

                        List<LawInputDTO> Lawinputdtos = new List<LawInputDTO>();

                        LawInputDTO Lawinputdto = new LawInputDTO();
                        foreach (LawRecord item in lawrecords)
                        {
                            idssss = item.Id;
                            cccc = item.content;
                            if (item.content.Contains("超过最大限制数"))
                            {
                                _lawrecordrepository.GetDbContext().Database.ExecuteSqlRaw("delete from  LawRecord  where Id='" + item.Id + "'");
                                Console.WriteLine("删除超过最大限制数，" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                Lawinputdto = new LawInputDTO();
                                Lawinputdto.Id = item.Id;
                                continue;
                            }
                            if (!item.content.Contains("wjhmiss"))
                            {
                                _lawrecordrepository.GetDbContext().Database.ExecuteSqlRaw("delete from  LawRecord  where Id='" + item.Id + "'");
                                Console.WriteLine("删除wjhmiss，" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                Lawinputdto = new LawInputDTO();
                                Lawinputdto.Id = item.Id;
                                continue;
                            }
                            //
                            if (item.content.ToUpper().Contains("</TABLE>") && item.content.ToUpper().Contains("</TBODY>"))
                            {
                                _lawrecordrepository.GetDbContext().Database.ExecuteSqlRaw("update LawRecord set Indexed = 9999 where Id='" + item.Id + "'");
                                continue;
                            }

                            //var document = new HtmlDocument { OptionAutoCloseOnEnd = true };
                            //document.LoadHtml(item.content.Replace("\r", "").Replace("\n", ""));
                            //HtmlNodeCollection panelBodys = document.DocumentNode.SelectNodes("//div[@class='law-title']");
                            //HtmlNode panelBodys1 = document.DocumentNode.SelectSingleNode("//div[@class='law-title']");


                            srows += 1;
                            Console.WriteLine("总数：" + taltal.ToString() + ",当前第" + srows.ToString() + " /" + srowtotl.ToString() + ",剩下:" + (taltal - srows).ToString() + "，indexed:" + indexed + ",id:" + idssss + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));

                            List<LawInputDetailDTO> Lawinputdetaildtos = new List<LawInputDetailDTO>();
                            Lawinputdto = new LawInputDTO();
                            #region
                            if (item.type == "gjfl")
                            {
                                Lawinputdto.type = "国家法律";  // 大类：国家法律 ，地方法规，立法资料，司法资料
                            }
                            if (item.type == "dffg")
                            {
                                Lawinputdto.type = "地方法规";  // 大类：国家法律 ，地方法规，立法资料，司法资料
                            }
                            if (item.type == "lfzl")
                            {
                                Lawinputdto.type = "立法资料";  // 大类：国家法律 ，地方法规，立法资料，司法资料
                            }
                            if (item.type == "sfzl")
                            {
                                Lawinputdto.type = "司法资料";  // 大类：国家法律 ，地方法规，立法资料，司法资料
                            }
                            if (item.subtype == "010101")
                            {
                                Lawinputdto.subtype = "立法解释"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010102")
                            {
                                Lawinputdto.subtype = "司法解释"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010103")
                            {
                                Lawinputdto.subtype = "行政法规"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010104")
                            {
                                Lawinputdto.subtype = "部门规章"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010105")
                            {
                                Lawinputdto.subtype = "其他"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010201")
                            {
                                Lawinputdto.subtype = "地方性法规"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010202")
                            {
                                Lawinputdto.subtype = "地方政府规章"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010203")
                            {
                                Lawinputdto.subtype = "地方司法文件"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010204")
                            {
                                Lawinputdto.subtype = "地方规范性文件"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            //if (item.subtype == "010205")
                            //{
                            //    Lawinputdto.subtype = "北京"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            //}
                            if (item.subtype == "010301")
                            {
                                Lawinputdto.subtype = "全国人大立法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010302")
                            {
                                Lawinputdto.subtype = "中央行政立法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010303")
                            {
                                Lawinputdto.subtype = "地方人大立法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010304")
                            {
                                Lawinputdto.subtype = "地方行政立法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010305")
                            {
                                Lawinputdto.subtype = "其他"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010401")
                            {
                                Lawinputdto.subtype = "两高司法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            if (item.subtype == "010402")
                            {
                                Lawinputdto.subtype = "地方司法资料"; //小类：（国家法律）法律立法解释 司法解释 行政法规 部门规章 其他文件
                            }
                            Lawinputdto.area = item.area;
                            #endregion
                            if (item.type == "gjfl")
                            {
                                ISelectable Selectable = new HtmlSelectable(item.content.Replace("<%", ""));
                                Lawinputdto.Id = item.Id;
                                Lawinputdto.name = Selectable.Select(Selectors.XPath("//div[@class='law-title']"))?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("法信", "律格尔");  //= 中华人民共和国民法典
                            
                                Lawinputdto.historys = new List<historyDTO>();
                                var list = Selectable.Select(Selectors.XPath("//div[@class='js-sxTab']")).SelectList(Selectors.XPath("//div")).ToList();
                                foreach (var div in list)
                                {
                                    if (((HtmlSelectable)div).Node.Attributes["class"] != null && ((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("nat-listMod") >= 0)
                                    {
                                        var Lis = div.SelectList(Selectors.XPath("//li")).ToList();
                                        foreach (var items in Lis)
                                        {
                                            string name = string.Empty;
                                            string value = string.Empty;
                                            foreach (var div2 in items.Nodes().ToList())
                                            {
                                                var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                if (tmm != null && tmm.Value.IndexOf("nop-t1") >= 0)
                                                {
                                                    name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                }
                                                if (tmm != null && tmm.Value.IndexOf("nop-t2") >= 0)
                                                {
                                                    value = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                }
                                            }
                                            if (!string.IsNullOrEmpty(name))
                                            {
                                                if (name.IndexOf("机关") >= 0)
                                                {
                                                    value = value.Replace(" ", "").Replace(emm, "").Replace("，", ",").Replace(";", ",").Replace("；", ",").Replace("。", ",").Replace(".", ",");
                                                    //Lawinputdto.authority = value.Split(',',StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  
                                                    var authoritys = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                    Lawinputdto.authority = new List<string>();
                                                    string strtext = string.Empty;
                                                    foreach (var au in authoritys)
                                                    {
                                                        LawAuthority ls = _baseDatasHelper.GetLawAuthority().Where(m => m.name == au).FirstOrDefault();
                                                        if (ls != null)
                                                        {
                                                            strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                            Lawinputdto.authority.Add(strtext);
                                                            if (ls.pid == "A")
                                                            {
                                                                continue;
                                                            }
                                                            if (ls.parentLawAuthority != null)
                                                            {
                                                                strtext = ls.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.name : ls.parentLawAuthority.name + "-" + ls.parentLawAuthority.Id;
                                                                Lawinputdto.authority.Add(strtext);
                                                                if (ls.parentLawAuthority.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawAuthority.parentLawAuthority != null)
                                                                {
                                                                    strtext = ls.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.Id;
                                                                    Lawinputdto.authority.Add(strtext);
                                                                    if (ls.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                    {
                                                                        strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                        Lawinputdto.authority.Add(strtext);
                                                                        if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                        {
                                                                            strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                            Lawinputdto.authority.Add(strtext);
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                            {
                                                                                strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                Lawinputdto.authority.Add(strtext);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (name.IndexOf("施行日期") >= 0)
                                                {
                                                    Lawinputdto.effective_date = todate(value); // "2017-11-04" 生效日期

                                                }
                                                else if (name.IndexOf("公布日期") >= 0)
                                                {
                                                    Lawinputdto.posting_date = todate(value); //= "2017年11月04日"  发布

                                                }
                                                else if (name.IndexOf("文号") >= 0)
                                                {
                                                    Lawinputdto.document_number = value; //= 文号   中华人民共和国主席令第四十五号， "主席令第80号"

                                                }
                                                else if (name.IndexOf("效力等级") >= 0)
                                                {
                                                    Lawinputdto.eff_level = new List<string>(); //= 效力等级 法律
                                                    Laweff_level ls = _baseDatasHelper.GetLaweff_level().Where(m => m.name == value).FirstOrDefault();
                                                    string strtext = string.Empty;
                                                    if (ls != null)
                                                    {
                                                        strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                        Lawinputdto.eff_level.Add(strtext);
                                                        if (ls.pid != "A")
                                                        {
                                                            if (ls.parentLaweff_level != null)
                                                            {
                                                                strtext = ls.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.name : ls.parentLaweff_level.name + "-" + ls.parentLaweff_level.Id;
                                                                Lawinputdto.eff_level.Add(strtext);
                                                                if (ls.parentLaweff_level.pid != "A")
                                                                {
                                                                    if (ls.parentLaweff_level.parentLaweff_level != null)
                                                                    {
                                                                        strtext = ls.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.Id;
                                                                        Lawinputdto.eff_level.Add(strtext);
                                                                        if (ls.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                        {
                                                                            if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                            {
                                                                                strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                Lawinputdto.eff_level.Add(strtext);
                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                {
                                                                                    if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                    {
                                                                                        strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                        Lawinputdto.eff_level.Add(strtext);
                                                                                        if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                        {
                                                                                            if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                            {
                                                                                                strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                                Lawinputdto.eff_level.Add(strtext);
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }

                                                                            }
                                                                        }

                                                                    }
                                                                }

                                                            }
                                                        }

                                                    }



                                                }
                                                else if (name.IndexOf("时效性") >= 0)
                                                {
                                                    Lawinputdto.time_limited = value; //= 现行有效  失效   已被修改 尚未生效 部分失效  实际失效 

                                                }
                                                else if (name.IndexOf("分类") >= 0)
                                                {
                                                    //value = value.Replace("，", ",").Replace(";", ",").Replace("；", ",").Replace("。", ",").Replace(".", ",");
                                                    //Lawinputdto.lawtype = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();  //= 主题分类   民法商法总类   ,犯罪和刑事责任, 畜牧业, 社会救助等等

                                                    var lawtypes = value.Replace(" ", "").Replace(emm, "").Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                    Lawinputdto.lawtype = new List<string>();
                                                    string strtext = string.Empty;
                                                    foreach (var au in lawtypes)
                                                    {
                                                        LawType ls = _baseDatasHelper.GetLawType().Where(m => m.name == au).FirstOrDefault();
                                                        if (ls != null)
                                                        {
                                                            strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                            Lawinputdto.lawtype.Add(strtext);
                                                            if (ls.pid == "A")
                                                            {
                                                                continue;
                                                            }
                                                            if (ls.parentLawType != null)
                                                            {
                                                                strtext = ls.parentLawType.name.Contains("-") ? ls.parentLawType.name : ls.parentLawType.name + "-" + ls.parentLawType.Id;
                                                                Lawinputdto.lawtype.Add(strtext);
                                                                if (ls.parentLawType.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawType.parentLawType != null)
                                                                {
                                                                    strtext = ls.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.Id;
                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                    if (ls.parentLawType.parentLawType.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawType.parentLawType.parentLawType != null)
                                                                    {
                                                                        strtext = ls.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.Id;
                                                                        Lawinputdto.lawtype.Add(strtext);
                                                                        if (ls.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                        {
                                                                            strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                            Lawinputdto.lawtype.Add(strtext);
                                                                            if (ls.parentLawType.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                            {
                                                                                strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                Lawinputdto.lawtype.Add(strtext);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    throw new Exception("简介名称不包含363" + name);
                                                }
                                            }
                                        }
                                    }
                                    if (((HtmlSelectable)div).Node.Attributes["class"] != null && ((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("timeMod") >= 0)
                                    {
                                        var Listorys = div.SelectList(Selectors.XPath("//div")).ToList();
                                        historyDTO hi;

                                        foreach (var div2 in Listorys.ToList())
                                        {
                                            hi = new historyDTO();
                                            var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                            if (tmm != null && tmm.Value.IndexOf("time-t1") >= 0)
                                            {
                                                hi.effective_date = todate(div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", ""));
                                            }
                                            if (tmm != null && tmm.Value.IndexOf("time-t3") >= 0)
                                            {
                                                hi.name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");

                                                var a = div2.Select(Selectors.XPath("//a"));
                                                if (a != null)
                                                {
                                                    string href = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                    hi.id = href.Substring(href.IndexOf("(\"") + 2, href.Length - href.IndexOf("\",") + 1);
                                                    Lawinputdto.historys.Add(hi);
                                                }
                                            }
                                        }
                                    }
                                }



                                Lawinputdto.alias_titles = new List<string>();
                                string ttt = Lawinputdto.name.Replace("(", "（").Replace(")", "）");
                                Lawinputdto.alias_titles.Add(ttt);
                                 

                                MatchCollection mctname = Regex.Matches(ttt, "《.{1,}?》");  //有问题
                                for (int j = 0; j < mctname.Count; j++)
                                {
                                    string Alianame = mctname[j].Groups[0].Value;
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                if (ttt.IndexOf("——") >= 0 )
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("——") + 2, ttt.Length - ttt.IndexOf("——") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }
                                if (ttt.IndexOf("－－") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("－－") + 2, ttt.Length - ttt.IndexOf("－－") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }
                                
                                if (ttt.IndexOf("中华人民共和国") >= 0)
                                {
                                    string  Alianame = ttt.Substring(ttt.IndexOf("中华人民共和国") + 7, ttt.Length - ttt.IndexOf("中华人民共和国") - 7);
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }
                                Lawinputdto.navcontent = item.GetNavContent;
                                Lawinputdto.liblink = new List<historyDTO>();

                                if (!string.IsNullOrEmpty(item.GetLibLink))
                                {
                                    ISelectable liblinkselectable = new HtmlSelectable(item.GetLibLink);
                                    if (liblinkselectable.SelectList(Selectors.XPath("//a")) != null)
                                    {
                                        var lilis = liblinkselectable.SelectList(Selectors.XPath("//a")).ToList();
                                        historyDTO dd;
                                        foreach (var lili in lilis)
                                        {
                                            dd = new historyDTO();
                                            dd.name = ((HtmlSelectable)lili).Node.Attributes["title"].Value;
                                            string temphref = ((HtmlSelectable)lili).Node.Attributes["href"].Value;
                                            dd.id = temphref.Substring(temphref.IndexOf("gid=") + 4, temphref.IndexOf("&") - temphref.IndexOf("gid=") - 4);
                                            Lawinputdto.liblink.Add(dd);
                                        }
                                    }
                                }

                                LawInputDetailDTO Lawdetailinputdto;

                                var content = Selectable.Select(Selectors.XPath("//div[@class='box fulltext']"));
                                string temp = string.Empty;
                                string temptiao = string.Empty;
                                string temptiaoint = string.Empty;
                                bool istiao = false;
                                int o = 0;
                                foreach (var tiao in content.Nodes().ToList())
                                {
                                    Lawdetailinputdto = new LawInputDetailDTO();
                                    Lawdetailinputdto.name = Lawinputdto.name;
                                    Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                    Lawdetailinputdto.pid = Lawinputdto.Id;
                                    Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                    string cont = ((HtmlSelectable)tiao).Node.OuterHtml;
                                    var tmm = ((HtmlSelectable)tiao).Node.Attributes["class"];

                                    if (istiao)
                                    {
                                        temp = temp + cont;
                                    }

                                    if (tmm != null && tmm.Value == "sp_wt_class")
                                    {
                                        if (!string.IsNullOrEmpty(temp))
                                        {
                                            Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                            Lawdetailinputdto.text = temp; //": "ffff"
                                            Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                            Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                            Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                            Lawinputdetaildtos.Add(Lawdetailinputdto);
                                            temp = "";
                                            Lawdetailinputdto = new LawInputDetailDTO();
                                            Lawdetailinputdto.name = Lawinputdto.name;
                                            Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                            Lawdetailinputdto.pid = Lawinputdto.Id;
                                            Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                        }
                                        foreach (var itemff in tiao.Nodes().ToList())
                                        {
                                            var tff = ((HtmlSelectable)itemff).Node.Attributes["class"];
                                            var tffva = itemff?.Value;
                                            string contff = ((HtmlSelectable)itemff).Node.OuterHtml;
                                            if (tff != null && tff.Value == "c_tiao")
                                            {
                                                Lawdetailinputdto.tiao = tffva.Replace(" ", "").Replace(emm, "");
                                            }
                                            else if (tff != null && tff.Value == "dt")
                                            {
                                                var id = ((HtmlSelectable)itemff).Node.Attributes["id"]?.Value.Replace("t_", "");
                                                if (id == null)
                                                {
                                                    MatchCollection mctou = Regex.Matches(((HtmlSelectable)itemff).Node.OuterHtml, "id=\".*?\"");
                                                    for (int i3 = 0; i3 < mctou.Count; i3++)
                                                    {
                                                        id = mctou[0].Groups[0].Value.Replace(" ", "").Replace(emm, "").Replace("\"", "").Replace("id=", "").Replace("t_", "");
                                                    }
                                                }
                                                Lawdetailinputdto.tiaoint = id;
                                            }
                                            else if (tffva.Length > 3)
                                            {
                                            }
                                        }
                                        Lawdetailinputdto.text = tiao.Value;
                                        Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                        Lawdetailinputdto.outerHtml = cont;
                                        Lawdetailinputdto.lawdetailotherinputdtos = new List<LawDetailOtherInputDTO>();
                                        List<LawRecordOther> LawRecordOthers = _lawrecordotherrepository.GetAllList(p => p.Pid == item.Id && p.tiao == Lawdetailinputdto.tiaoint);
                                        LawDetailOtherInputDTO others;
                                        foreach (var oitem in LawRecordOthers)
                                        {
                                            if (oitem.type == "法律关联法条")
                                            {
                                                try
                                                {
                                                    JObject jdoc = JObject.Parse(oitem.content);
                                                    JArray jarrayList = (JArray)jdoc["datas"];
                                                    foreach (var oth in jarrayList)
                                                    {
                                                        others = new LawDetailOtherInputDTO();
                                                        string tempid = (oth["contentlink"].ToString() + oth["link_file_id"].ToString());
                                                        others.id = tempid.Substring(tempid.IndexOf("gid=") + 4);
                                                        others.name = oth["link_title"].ToString();
                                                        others.tiao = oth["link_tiao_num"].ToString();
                                                        others.effective_date = todate(oth["link_sdate"]);
                                                        others.posting_date = todate(oth["link_fdate"]);
                                                        others.document_number = oth["link_wh"].ToString();
                                                        others.content = oth["link_content"].ToString();
                                                        string temps1 = oth["link_shixiao"].ToString();
                                                        if (temps1.IndexOf("'>") > 0)
                                                        {
                                                            others.time_limited = temps1.Substring(temps1.IndexOf("'>") + 2, temps1.IndexOf("</a>") - temps1.IndexOf("'>") - 2);

                                                        }
                                                        string temps = oth["link_xiaoli"].ToString();
                                                        if (temps.IndexOf("'>") > 0)
                                                        {
                                                            others.othertype = temps.Substring(temps.IndexOf("'>") + 2, temps.IndexOf("</a>") - temps.IndexOf("'>") - 2);//法律
                                                        }
                                                        others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                        Lawdetailinputdto.lawdetailotherinputdtos.Add(others);

                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine("'法律关联法条-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                    Logger.Warn("'法律关联法条-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                }

                                            }
                                            if (oitem.type == "释义")
                                            {
                                                try
                                                {
                                                    if (!string.IsNullOrEmpty(oitem.content))
                                                    {
                                                        others = new LawDetailOtherInputDTO();
                                                        ISelectable shiyiSelectable = new HtmlSelectable("<div>" + oitem.content + "</div>");
                                                        var con = shiyiSelectable.Select(Selectors.XPath("//div[@class='bd content']")); //= 中华人民共和国民法典

                                                        others.name = con.Select(Selectors.XPath("//div[1]/div[1]")).Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("&nbsp;", ""); ;
                                                        others.content = ((HtmlSelectable)con.Select(Selectors.XPath("//div[1]/div[2]"))).OuterHtml;
                                                        others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                        Lawdetailinputdto.lawdetailotherinputdtos.Add(others);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine("'释义-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                    Logger.Warn("'释义-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                }

                                            }
                                            if (oitem.type == "沿革信息")
                                            {
                                                if (!string.IsNullOrEmpty(oitem.content))
                                                {
                                                    try
                                                    {
                                                        ISelectable shiyiSelectable = new HtmlSelectable("<div>" + oitem.content + "</div>");
                                                        if (shiyiSelectable.SelectList(Selectors.XPath("//div[@class='item_box']")) != null)
                                                        {
                                                            var con = shiyiSelectable.SelectList(Selectors.XPath("//div[@class='item_box']")).ToList(); //= 中华人民共和国民法典
                                                            foreach (var it in con)
                                                            {
                                                                others = new LawDetailOtherInputDTO();
                                                                var a = it.Select(Selectors.XPath("//a[@class='alink']"));
                                                                string tt = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                                //href='javascript:FXC("A272703","1")'
                                                                others.id = tt.Substring(tt.IndexOf("(\"") + 2, tt.IndexOf("\",") - tt.IndexOf("(\"") - 2);
                                                                others.name = a.Value.Substring(0, a.Value.IndexOf("["));
                                                                var ss = it.SelectList(Selectors.XPath("//div")).ToList();
                                                                foreach (var sdf in ss)
                                                                {
                                                                    if (((HtmlSelectable)sdf).Node.Attributes["class"] != null)
                                                                    {
                                                                        var s = ((HtmlSelectable)sdf).Node.Attributes["class"].Value;
                                                                        if (s.IndexOf("content") >= 0)
                                                                        {
                                                                            others.content = sdf.Value;
                                                                        }
                                                                    }
                                                                }
                                                                others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                                Lawdetailinputdto.lawdetailotherinputdtos.Add(others);
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Console.WriteLine("'沿革信息-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                        Logger.Warn("'沿革信息-" + item.Id + "-" + Lawdetailinputdto.tiaoint + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                    }
                                                }
                                            }
                                        }
                                        Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                        Lawinputdetaildtos.Add(Lawdetailinputdto);
                                        istiao = false;
                                        temp = "";
                                    }
                                    else if (tmm != null && tmm.Value == "c_tiao")
                                    {
                                        if (!string.IsNullOrEmpty(temp))
                                        {
                                            Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                            Lawdetailinputdto.text = temp; //": "ffff"
                                            Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                            Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                            Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                            Lawinputdetaildtos.Add(Lawdetailinputdto);
                                            temp = "";
                                            Lawdetailinputdto = new LawInputDetailDTO();
                                            Lawdetailinputdto.name = Lawinputdto.name;
                                            Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                            Lawdetailinputdto.pid = Lawinputdto.Id;
                                            Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                        }

                                        temp = cont;
                                        istiao = true;
                                        temptiao = tiao.Value.Replace(" ", "").Replace(emm, "");
                                    }
                                    else if (tmm != null && tmm.Value == "dt")
                                    {
                                        Lawdetailinputdto.tiao = temptiao.Replace(" ", "").Replace(emm, ""); //": "第一百一十五条",
                                        Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                        Lawdetailinputdto.text = temp; //": "ffff"
                                        Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                        var id = ((HtmlSelectable)tiao).Node.Attributes["id"]?.Value.Replace("t_", "");
                                        if (id == null)
                                        {
                                            MatchCollection mctou = Regex.Matches(((HtmlSelectable)tiao).Node.OuterHtml, "id=\".*?\"");
                                            for (int i3 = 0; i3 < mctou.Count; i3++)
                                            {
                                                id = mctou[0].Groups[0].Value.Replace(" ", "").Replace(emm, "").Replace("\"", "").Replace("id=", "").Replace("t_", "");
                                            }
                                        }
                                        Lawdetailinputdto.tiaoint = id;

                                        Lawdetailinputdto.lawdetailotherinputdtos = new List<LawDetailOtherInputDTO>();
                                        List<LawRecordOther> LawRecordOthers = _lawrecordotherrepository.GetAllList(p => p.Pid == item.Id && p.tiao == id);
                                        LawDetailOtherInputDTO others;
                                        foreach (var oitem in LawRecordOthers)
                                        {
                                            if (oitem.type == "法律关联法条")
                                            {
                                                try
                                                {
                                                    JObject jdoc = JObject.Parse(oitem.content);
                                                    JArray jarrayList = (JArray)jdoc["datas"];
                                                    foreach (var oth in jarrayList)
                                                    {
                                                        others = new LawDetailOtherInputDTO();
                                                        string tempid = (oth["contentlink"].ToString() + oth["link_file_id"].ToString());
                                                        others.id = tempid.Substring(tempid.IndexOf("gid=") + 4);
                                                        others.name = oth["link_title"].ToString();
                                                        others.tiao = oth["link_tiao_num"].ToString();
                                                        others.effective_date = todate(oth["link_sdate"]);
                                                        others.posting_date = todate(oth["link_fdate"]);
                                                        others.document_number = oth["link_wh"].ToString();
                                                        others.content = oth["link_content"].ToString();
                                                        string temps1 = oth["link_shixiao"].ToString();
                                                        if (temps1.IndexOf("'>") > 0)
                                                        {
                                                            others.time_limited = temps1.Substring(temps1.IndexOf("'>") + 2, temps1.IndexOf("</a>") - temps1.IndexOf("'>") - 2);

                                                        }
                                                        string temps = oth["link_xiaoli"].ToString();
                                                        if (temps.IndexOf("'>") > 0)
                                                        {
                                                            others.othertype = temps.Substring(temps.IndexOf("'>") + 2, temps.IndexOf("</a>") - temps.IndexOf("'>") - 2);//法律
                                                        }
                                                        others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                        Lawdetailinputdto.lawdetailotherinputdtos.Add(others);

                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine("'法律关联法条-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                    Logger.Warn("'法律关联法条-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));

                                                }

                                            }
                                            if (oitem.type == "释义")
                                            {
                                                try
                                                {
                                                    if (!string.IsNullOrEmpty(oitem.content))
                                                    {
                                                        others = new LawDetailOtherInputDTO();
                                                        ISelectable shiyiSelectable = new HtmlSelectable("<div>" + oitem.content + "</div>");
                                                        var con = shiyiSelectable.Select(Selectors.XPath("//div[@class='bd content']")); //= 中华人民共和国民法典

                                                        others.name = con.Select(Selectors.XPath("//div[1]/div[1]")).Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("&nbsp;", ""); ;
                                                        others.content = ((HtmlSelectable)con.Select(Selectors.XPath("//div[1]/div[2]"))).OuterHtml;
                                                        others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                        Lawdetailinputdto.lawdetailotherinputdtos.Add(others);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine("'释义-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                    Logger.Warn("'释义-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));

                                                }

                                            }
                                            if (oitem.type == "沿革信息")
                                            {
                                                if (!string.IsNullOrEmpty(oitem.content))
                                                {
                                                    try
                                                    {
                                                        ISelectable shiyiSelectable = new HtmlSelectable("<div>" + oitem.content + "</div>");
                                                        if (shiyiSelectable.SelectList(Selectors.XPath("//div[@class='item_box']")) != null)
                                                        {
                                                            var con = shiyiSelectable.SelectList(Selectors.XPath("//div[@class='item_box']")).ToList(); //= 中华人民共和国民法典
                                                            foreach (var it in con)
                                                            {
                                                                others = new LawDetailOtherInputDTO();
                                                                var a = it.Select(Selectors.XPath("//a[@class='alink']"));
                                                                string tt = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                                //href='javascript:FXC("A272703","1")'
                                                                others.id = tt.Substring(tt.IndexOf("(\"") + 2, tt.IndexOf("\",") - tt.IndexOf("(\"") - 2);
                                                                others.name = a.Value.Substring(0, a.Value.IndexOf("["));
                                                                var ss = it.SelectList(Selectors.XPath("//div")).ToList();
                                                                foreach (var sdf in ss)
                                                                {
                                                                    if (((HtmlSelectable)sdf).Node.Attributes["class"] != null)
                                                                    {
                                                                        var s = ((HtmlSelectable)sdf).Node.Attributes["class"].Value;
                                                                        if (s.IndexOf("content") >= 0)
                                                                        {
                                                                            others.content = sdf.Value;
                                                                        }
                                                                    }
                                                                }
                                                                others.type = oitem.type;//": 法律关联法条   释义   沿革信息
                                                                Lawdetailinputdto.lawdetailotherinputdtos.Add(others);
                                                            }
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Console.WriteLine("'沿革信息-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                                                        Logger.Warn("'沿革信息-" + item.Id + "-" + id + "','" + ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));

                                                    }

                                                }
                                            }
                                        }
                                        Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                        Lawinputdetaildtos.Add(Lawdetailinputdto);
                                        istiao = false;
                                        temp = "";
                                    }
                                    else if (!istiao)
                                    {
                                        temp = temp + cont;
                                    }

                                    o += 1;
                                }
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    Lawdetailinputdto = new LawInputDetailDTO();
                                    Lawdetailinputdto.name = Lawinputdto.name;
                                    Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                    Lawdetailinputdto.pid = Lawinputdto.Id;
                                    Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                    Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                    Lawdetailinputdto.text = temp; //": "ffff"
                                    Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                    Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                    Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                    Lawinputdetaildtos.Add(Lawdetailinputdto);
                                }
                            }
                            if (item.type == "dffg")
                            {
                                ISelectable Selectable = new HtmlSelectable(item.content.Replace("<%", "").Replace("%>", ""));

                                Lawinputdto.Id = item.Id;
                                Lawinputdto.name = Selectable.Select(Selectors.XPath("//div[@class='law-title']"))?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("法信", "律格尔"); //= 中华人民共和国民法典
                                Lawinputdto.historys = new List<historyDTO>();
                                var list = Selectable.Select(Selectors.XPath("//div[@class='js-sxTab']")).SelectList(Selectors.XPath("//div")).ToList();
                                foreach (var div in list)
                                {
                                    if (((HtmlSelectable)div).Node.Attributes["class"] != null)
                                    {
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("nat-listMod") >= 0)
                                        {
                                            var Lis = div.SelectList(Selectors.XPath("//li")).ToList();
                                            foreach (var items in Lis)
                                            {
                                                string name = string.Empty;
                                                string value = string.Empty;
                                                foreach (var div2 in items.Nodes().ToList())
                                                {
                                                    var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t1") >= 0)
                                                    {
                                                        name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t2") >= 0)
                                                    {
                                                        value = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                }
                                                if (!string.IsNullOrEmpty(name))
                                                {
                                                    if (name.IndexOf("机关") >= 0)
                                                    {
                                                        value = value.Replace(" ", "").Replace(emm, "").Replace("，", ",").Replace(";", ",").Replace("；", ",").Replace("。", ",").Replace(".", ",");
                                                        //Lawinputdto.authority = value.Split(',',StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  
                                                        var authoritys = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.authority = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in authoritys)
                                                        {
                                                            LawAuthority ls = _baseDatasHelper.GetLawAuthority().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.authority.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawAuthority != null)
                                                                {
                                                                    strtext = ls.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.name : ls.parentLawAuthority.name + "-" + ls.parentLawAuthority.Id;
                                                                    Lawinputdto.authority.Add(strtext);
                                                                    if (ls.parentLawAuthority.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawAuthority.parentLawAuthority != null)
                                                                    {
                                                                        strtext = ls.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.Id;
                                                                        Lawinputdto.authority.Add(strtext);
                                                                        if (ls.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                        {
                                                                            strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                            Lawinputdto.authority.Add(strtext);
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                            {
                                                                                strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                Lawinputdto.authority.Add(strtext);
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                                {
                                                                                    strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                    Lawinputdto.authority.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else if (name.IndexOf("施行日期") >= 0)
                                                    {
                                                        Lawinputdto.effective_date = todate(value); // "2017-11-04" 生效日期

                                                    }
                                                    else if (name.IndexOf("公布日期") >= 0)
                                                    {
                                                        Lawinputdto.posting_date = todate(value); //= "2017年11月04日"  发布

                                                    }
                                                    else if (name.IndexOf("文号") >= 0)
                                                    {
                                                        Lawinputdto.document_number = value; //= 文号   中华人民共和国主席令第四十五号， "主席令第80号"

                                                    }
                                                    else if (name.IndexOf("效力等级") >= 0)
                                                    {
                                                        Lawinputdto.eff_level = new List<string>(); //= 效力等级 法律
                                                        Laweff_level ls = _baseDatasHelper.GetLaweff_level().Where(m => m.name == value).FirstOrDefault();
                                                        string strtext = string.Empty;
                                                        if (ls != null)
                                                        {
                                                            strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                            Lawinputdto.eff_level.Add(strtext);
                                                            if (ls.pid != "A")
                                                            {
                                                                if (ls.parentLaweff_level != null)
                                                                {
                                                                    strtext = ls.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.name : ls.parentLaweff_level.name + "-" + ls.parentLaweff_level.Id;
                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                    if (ls.parentLaweff_level.pid != "A")
                                                                    {
                                                                        if (ls.parentLaweff_level.parentLaweff_level != null)
                                                                        {
                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.Id;
                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                            if (ls.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                            {
                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                {
                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                    if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                    {
                                                                                        if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                        {
                                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                                            if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                            {
                                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                                {
                                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }

                                                                                }
                                                                            }

                                                                        }
                                                                    }

                                                                }
                                                            }

                                                        }

                                                    }
                                                    else if (name.IndexOf("时效性") >= 0)
                                                    {
                                                        Lawinputdto.time_limited = value; //= 现行有效  失效   已被修改 尚未生效 部分失效  实际失效 

                                                    }
                                                    else if (name.IndexOf("分类") >= 0)
                                                    {
                                                        var lawtypes = value.Replace(" ", "").Replace(emm, "").Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.lawtype = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in lawtypes)
                                                        {
                                                            LawType ls = _baseDatasHelper.GetLawType().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.lawtype.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawType != null)
                                                                {
                                                                    strtext = ls.parentLawType.name.Contains("-") ? ls.parentLawType.name : ls.parentLawType.name + "-" + ls.parentLawType.Id;
                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                    if (ls.parentLawType.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawType.parentLawType != null)
                                                                    {
                                                                        strtext = ls.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.Id;
                                                                        Lawinputdto.lawtype.Add(strtext);
                                                                        if (ls.parentLawType.parentLawType.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawType.parentLawType.parentLawType != null)
                                                                        {
                                                                            strtext = ls.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.Id;
                                                                            Lawinputdto.lawtype.Add(strtext);
                                                                            if (ls.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                            {
                                                                                strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                Lawinputdto.lawtype.Add(strtext);
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                                {
                                                                                    strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        throw new Exception("简介名称不包含");
                                                    }
                                                }
                                            }
                                        }
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("timeMod") >= 0)
                                        {
                                            var Listorys = div.SelectList(Selectors.XPath("//div")).ToList();
                                            historyDTO hi = new historyDTO();

                                            foreach (var div2 in Listorys.ToList())
                                            {
                                                var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                if (tmm != null && tmm.Value.IndexOf("time-t1") >= 0)
                                                {
                                                    hi.effective_date = todate(div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", ""));
                                                }
                                                if (tmm != null && tmm.Value.IndexOf("time-t3") >= 0)
                                                {
                                                    hi.name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");

                                                    var a = div2.Select(Selectors.XPath("//a"));
                                                    string href = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                    hi.id = href.Substring(href.IndexOf("(\"") + 2, href.Length - href.IndexOf("\",") + 1);
                                                }

                                            }
                                            Lawinputdto.historys.Add(hi);
                                        }
                                    }
                                }


                                Lawinputdto.alias_titles = new List<string>();
                                string ttt = Lawinputdto.name.Replace("(", "（").Replace(")", "）");
                                Lawinputdto.alias_titles.Add(ttt);


                                MatchCollection mctname = Regex.Matches(ttt, "《.{1,}?》");  //有问题
                                for (int j = 0; j < mctname.Count; j++)
                                {
                                    string Alianame = mctname[j].Groups[0].Value;
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                if (ttt.IndexOf("——") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("——") + 2, ttt.Length - ttt.IndexOf("——") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }
                                if (ttt.IndexOf("－－") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("－－") + 2, ttt.Length - ttt.IndexOf("－－") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }

                                if (ttt.IndexOf("中华人民共和国") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("中华人民共和国") + 7, ttt.Length - ttt.IndexOf("中华人民共和国") - 7);
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }
                                 
                                var ad = Selectable.Select(Selectors.XPath("//div[@class='ml-list js_ml-list']"));
                                Lawinputdto.navcontent = ((HtmlSelectable)ad).Node.OuterHtml;




                                //Lawinputdto.Lawdetailinputdtos = new List<LawInputDetailDTO>();
                                LawInputDetailDTO Lawdetailinputdto;
                                var content = Selectable.Select(Selectors.XPath("//div[@class='box fulltext']"));
                                string temp = string.Empty;
                                string temptiao = string.Empty;
                                string temptiaoint = string.Empty;
                                bool istiao = false;
                                int o = 0;
                                foreach (var tiao in content.Nodes().ToList())
                                {
                                    Lawdetailinputdto = new LawInputDetailDTO();
                                    Lawdetailinputdto.name = Lawinputdto.name;
                                    Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                    Lawdetailinputdto.pid = Lawinputdto.Id;
                                    Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                    string cont = ((HtmlSelectable)tiao).Node.OuterHtml;
                                    var tmm = ((HtmlSelectable)tiao).Node.Attributes["class"];

                                    if (istiao)
                                    {
                                        temp = temp + cont;
                                    }

                                    if (tmm != null && tmm.Value == "sp_wt_class")
                                    {
                                        if (!string.IsNullOrEmpty(temp))
                                        {
                                            Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                            Lawdetailinputdto.text = temp; //": "ffff"
                                            Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                            Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                            Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                            Lawinputdetaildtos.Add(Lawdetailinputdto);
                                            temp = "";
                                            Lawdetailinputdto = new LawInputDetailDTO();
                                            Lawdetailinputdto.name = Lawinputdto.name;
                                            Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                            Lawdetailinputdto.pid = Lawinputdto.Id;
                                            Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                        }
                                        foreach (var itemff in tiao.Nodes().ToList())
                                        {
                                            var tff = ((HtmlSelectable)itemff).Node.Attributes["class"];
                                            var tffva = itemff?.Value;
                                            string contff = ((HtmlSelectable)itemff).Node.OuterHtml;
                                            if (tff != null && tff.Value == "c_tiao")
                                            {
                                                Lawdetailinputdto.tiao = tffva.Replace(" ", "").Replace(emm, "");
                                            }
                                            else if (tff != null && tff.Value == "dt")
                                            {
                                                var id = ((HtmlSelectable)itemff).Node.Attributes["id"].Value.Replace("t_", "");

                                                if (id == null)
                                                {
                                                    MatchCollection mctou = Regex.Matches(((HtmlSelectable)itemff).Node.OuterHtml, "id=\".*?\"");
                                                    for (int i3 = 0; i3 < mctou.Count; i3++)
                                                    {
                                                        id = mctou[0].Groups[0].Value.Replace(" ", "").Replace(emm, "").Replace("\"", "").Replace("id=", "").Replace("t_", "");
                                                    }
                                                }


                                                Lawdetailinputdto.tiaoint = id;
                                            }
                                            else if (tffva.Length > 3)
                                            {
                                            }
                                        }
                                        Lawdetailinputdto.text = tiao?.Value;
                                        Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                        Lawdetailinputdto.outerHtml = cont;
                                        Lawdetailinputdto.lawdetailotherinputdtos = new List<LawDetailOtherInputDTO>();
                                        Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                        Lawinputdetaildtos.Add(Lawdetailinputdto);
                                        istiao = false;
                                        temp = "";
                                    }
                                    else if (tmm != null && tmm.Value == "c_tiao")
                                    {
                                        if (!string.IsNullOrEmpty(temp))
                                        {
                                            Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                            Lawdetailinputdto.text = temp; //": "ffff"
                                            Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                            Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                            Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                            Lawinputdetaildtos.Add(Lawdetailinputdto);
                                            temp = "";
                                            Lawdetailinputdto = new LawInputDetailDTO();
                                            Lawdetailinputdto.name = Lawinputdto.name;
                                            Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                            Lawdetailinputdto.pid = Lawinputdto.Id;
                                            Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                        }

                                        temp = cont;
                                        istiao = true;
                                        temptiao = tiao.Value.Replace(" ", "").Replace(emm, "");
                                    }
                                    else if (tmm != null && tmm.Value == "dt")
                                    {
                                        Lawdetailinputdto.tiao = temptiao.Replace(" ", "").Replace(emm, ""); //": "第一百一十五条",
                                        Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                        Lawdetailinputdto.text = temp; //": "ffff"
                                        Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                        MatchCollection mct = Regex.Matches(((HtmlSelectable)tiao).Node.OuterHtml, "id=\".*?\"");
                                        string id = string.Empty;
                                        for (int i3 = 0; i3 < mct.Count; i3++)
                                        {
                                            id = mct[0].Groups[0].Value.Replace(" ", "").Replace(emm, "").Replace("\"", "").Replace("id=", "").Replace("t_", "");
                                        }
                                        Lawdetailinputdto.tiaoint = id;
                                        Lawdetailinputdto.lawdetailotherinputdtos = new List<LawDetailOtherInputDTO>();
                                        Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                        Lawinputdetaildtos.Add(Lawdetailinputdto);
                                        istiao = false;
                                        temp = "";
                                    }
                                    else if (!istiao)
                                    {
                                        temp = temp + cont;
                                    }
                                    o += 1;
                                }
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    Lawdetailinputdto = new LawInputDetailDTO();
                                    Lawdetailinputdto.name = Lawinputdto.name;
                                    Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                    Lawdetailinputdto.pid = Lawinputdto.Id;
                                    Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                    Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                    Lawdetailinputdto.text = temp; //": "ffff"
                                    Lawdetailinputdto.outerHtml = temp; //": "ffff"
                                    Lawdetailinputdto.order = o.ToString().PadLeft(5, '0');
                                    Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                    Lawinputdetaildtos.Add(Lawdetailinputdto);
                                }
                            }
                            if (item.type == "lfzl")
                            {

                                ISelectable Selectable = new HtmlSelectable(item.content.Replace("<%", ""));
                                Lawinputdto.Id = item.Id;
                                Lawinputdto.name = Selectable.Select(Selectors.XPath("//div[@class='law-content']")).Select(Selectors.XPath("//div[@class='law-title']"))?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("法信", "律格尔"); //= 中华人民共和国民法典
                                Lawinputdto.historys = new List<historyDTO>();
                                var list = Selectable.Select(Selectors.XPath("//div[@class='js-sxTab']")).SelectList(Selectors.XPath("//div")).ToList();
                                foreach (var div in list)
                                {
                                    if (((HtmlSelectable)div).Node.Attributes["class"] != null)
                                    {
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("nat-listMod") >= 0)
                                        {
                                            var Lis = div.SelectList(Selectors.XPath("//li")).ToList();
                                            foreach (var items in Lis)
                                            {
                                                string name = string.Empty;
                                                string value = string.Empty;
                                                foreach (var div2 in items.Nodes().ToList())
                                                {
                                                    var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t1") >= 0)
                                                    {
                                                        name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t2") >= 0)
                                                    {
                                                        value = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                }
                                                if (!string.IsNullOrEmpty(name))
                                                {
                                                    if (name.IndexOf("机关") >= 0)
                                                    {
                                                        value = value.Replace(" ", "").Replace(emm, "").Replace("，", ",").Replace(";", ",").Replace("；", ",").Replace("。", ",").Replace(".", ",");
                                                        //Lawinputdto.authority = value.Split(',',StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  
                                                        var authoritys = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.authority = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in authoritys)
                                                        {
                                                            LawAuthority ls = _baseDatasHelper.GetLawAuthority().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.authority.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawAuthority != null)
                                                                {
                                                                    strtext = ls.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.name : ls.parentLawAuthority.name + "-" + ls.parentLawAuthority.Id;
                                                                    Lawinputdto.authority.Add(strtext);
                                                                    if (ls.parentLawAuthority.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawAuthority.parentLawAuthority != null)
                                                                    {
                                                                        strtext = ls.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.Id;
                                                                        Lawinputdto.authority.Add(strtext);
                                                                        if (ls.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                        {
                                                                            strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                            Lawinputdto.authority.Add(strtext);
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                            {
                                                                                strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                Lawinputdto.authority.Add(strtext);
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                                {
                                                                                    strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                    Lawinputdto.authority.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else if (name.IndexOf("施行日期") >= 0)
                                                    {
                                                        Lawinputdto.effective_date = todate(value); // "2017-11-04" 生效日期

                                                    }
                                                    else if (name.IndexOf("公布日期") >= 0)
                                                    {
                                                        Lawinputdto.posting_date = todate(value); //= "2017年11月04日"  发布

                                                    }
                                                    else if (name.IndexOf("文号") >= 0)
                                                    {
                                                        Lawinputdto.document_number = value; //= 文号   中华人民共和国主席令第四十五号， "主席令第80号"

                                                    }
                                                    else if (name.IndexOf("效力等级") >= 0)
                                                    {
                                                        Lawinputdto.eff_level = new List<string>(); //= 效力等级 法律
                                                        Laweff_level ls = _baseDatasHelper.GetLaweff_level().Where(m => m.name == value).FirstOrDefault();
                                                        string strtext = string.Empty;
                                                        if (ls != null)
                                                        {
                                                            strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                            Lawinputdto.eff_level.Add(strtext);
                                                            if (ls.pid != "A")
                                                            {
                                                                if (ls.parentLaweff_level != null)
                                                                {
                                                                    strtext = ls.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.name : ls.parentLaweff_level.name + "-" + ls.parentLaweff_level.Id;
                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                    if (ls.parentLaweff_level.pid != "A")
                                                                    {
                                                                        if (ls.parentLaweff_level.parentLaweff_level != null)
                                                                        {
                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.Id;
                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                            if (ls.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                            {
                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                {
                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                    if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                    {
                                                                                        if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                        {
                                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                                            if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                            {
                                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                                {
                                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }

                                                                                }
                                                                            }

                                                                        }
                                                                    }

                                                                }
                                                            }

                                                        }

                                                    }
                                                    else if (name.IndexOf("时效性") >= 0)
                                                    {
                                                        Lawinputdto.time_limited = value; //= 现行有效  失效   已被修改 尚未生效 部分失效  实际失效 

                                                    }
                                                    else if (name.IndexOf("分类") >= 0)
                                                    {
                                                        var lawtypes = value.Replace(" ", "").Replace(emm, "").Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.lawtype = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in lawtypes)
                                                        {
                                                            LawType ls = _baseDatasHelper.GetLawType().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.lawtype.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawType != null)
                                                                {
                                                                    strtext = ls.parentLawType.name.Contains("-") ? ls.parentLawType.name : ls.parentLawType.name + "-" + ls.parentLawType.Id;
                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                    if (ls.parentLawType.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawType.parentLawType != null)
                                                                    {
                                                                        strtext = ls.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.Id;
                                                                        Lawinputdto.lawtype.Add(strtext);
                                                                        if (ls.parentLawType.parentLawType.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawType.parentLawType.parentLawType != null)
                                                                        {
                                                                            strtext = ls.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.Id;
                                                                            Lawinputdto.lawtype.Add(strtext);
                                                                            if (ls.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                            {
                                                                                strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                Lawinputdto.lawtype.Add(strtext);
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                                {
                                                                                    strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        throw new Exception("简介名称不包含");
                                                    }
                                                }
                                            }
                                        }
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("timeMod") >= 0)
                                        {
                                            var Listorys = div.SelectList(Selectors.XPath("//div")).ToList();
                                            historyDTO hi = new historyDTO();

                                            foreach (var div2 in Listorys.ToList())
                                            {
                                                var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                if (tmm != null && tmm.Value.IndexOf("time-t1") >= 0)
                                                {
                                                    hi.effective_date = todate(div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", ""));
                                                }
                                                if (tmm != null && tmm.Value.IndexOf("time-t3") >= 0)
                                                {
                                                    hi.name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");

                                                    var a = div2.Select(Selectors.XPath("//a"));
                                                    string href = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                    hi.id = href.Substring(href.IndexOf("(\"") + 2, href.Length - href.IndexOf("\",") + 1);
                                                }

                                            }
                                            Lawinputdto.historys.Add(hi);
                                        }
                                    }
                                }


                                Lawinputdto.alias_titles = new List<string>();
                                string ttt = Lawinputdto.name.Replace("(", "（").Replace(")", "）");
                                Lawinputdto.alias_titles.Add(ttt);


                                MatchCollection mctname = Regex.Matches(ttt, "《.{1,}?》");  //有问题
                                for (int j = 0; j < mctname.Count; j++)
                                {
                                    string Alianame = mctname[j].Groups[0].Value;
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                if (ttt.IndexOf("——") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("——") + 2, ttt.Length - ttt.IndexOf("——") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }
                                if (ttt.IndexOf("－－") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("－－") + 2, ttt.Length - ttt.IndexOf("－－") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }

                                if (ttt.IndexOf("中华人民共和国") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("中华人民共和国") + 7, ttt.Length - ttt.IndexOf("中华人民共和国") - 7);
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                //var ad = Selectable.Select(Selectors.XPath("//div[@class='ml-list js_ml-list']"));
                                //Lawinputdto.navcontent = ad.Value;


                                LawInputDetailDTO Lawdetailinputdto = new LawInputDetailDTO();
                                Lawdetailinputdto.name = Lawinputdto.name;
                                Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                Lawdetailinputdto.pid = Lawinputdto.Id;
                                Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                var content = Selectable.Select(Selectors.XPath("//div[@class='box fulltext']"));
                                Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                Lawdetailinputdto.text = ((HtmlSelectable)content).OuterHtml; //": "ffff"
                                Lawdetailinputdto.outerHtml = ((HtmlSelectable)content).OuterHtml; //": "ffff"
                                Lawdetailinputdto.order = "0";
                                Lawdetailinputdto.tiaoint = "0";
                                Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                Lawinputdetaildtos.Add(Lawdetailinputdto);

                            }
                            if (item.type == "sfzl")
                            {
                                ISelectable Selectable = new HtmlSelectable(item.content.Replace("<%", ""));
                                Lawinputdto.Id = item.Id;
                                Lawinputdto.name = Selectable.Select(Selectors.XPath("//div[@class='law-title']"))?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "").Replace("法信", "律格尔"); //= 中华人民共和国民法典
                                Lawinputdto.historys = new List<historyDTO>();
                                var list = Selectable.Select(Selectors.XPath("//div[@class='js-sxTab']")).SelectList(Selectors.XPath("//div")).ToList();
                                foreach (var div in list)
                                {
                                    if (((HtmlSelectable)div).Node.Attributes["class"] != null)
                                    {
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("nat-listMod") >= 0)
                                        {
                                            var Lis = div.SelectList(Selectors.XPath("//li")).ToList();
                                            foreach (var items in Lis)
                                            {
                                                string name = string.Empty;
                                                string value = string.Empty;
                                                foreach (var div2 in items.Nodes().ToList())
                                                {
                                                    var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t1") >= 0)
                                                    {
                                                        name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                    if (tmm != null && tmm.Value.IndexOf("nop-t2") >= 0)
                                                    {
                                                        value = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");
                                                    }
                                                }
                                                value = value.Replace("年", "-").Replace("月", "-").Replace("日", "-");


                                                if (!string.IsNullOrEmpty(name))
                                                {
                                                    if (name.IndexOf("机关") >= 0)
                                                    {
                                                        value = value.Replace(" ", "").Replace(emm, "").Replace("，", ",").Replace(";", ",").Replace("；", ",").Replace("。", ",").Replace(".", ",");
                                                        //Lawinputdto.authority = value.Split(',',StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  
                                                        var authoritys = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.authority = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in authoritys)
                                                        {
                                                            LawAuthority ls = _baseDatasHelper.GetLawAuthority().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.authority.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawAuthority != null)
                                                                {
                                                                    strtext = ls.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.name : ls.parentLawAuthority.name + "-" + ls.parentLawAuthority.Id;
                                                                    Lawinputdto.authority.Add(strtext);
                                                                    if (ls.parentLawAuthority.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawAuthority.parentLawAuthority != null)
                                                                    {
                                                                        strtext = ls.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.Id;
                                                                        Lawinputdto.authority.Add(strtext);
                                                                        if (ls.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                        {
                                                                            strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                            Lawinputdto.authority.Add(strtext);
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                            {
                                                                                strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                Lawinputdto.authority.Add(strtext);
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority != null)
                                                                                {
                                                                                    strtext = ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name.Contains("-") ? ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name : ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.name + "-" + ls.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.parentLawAuthority.Id;
                                                                                    Lawinputdto.authority.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else if (name.IndexOf("施行日期") >= 0)
                                                    {

                                                        Lawinputdto.effective_date = todate(value); // "2017-11-04" 生效日期
                                                    }
                                                    else if (name.IndexOf("公布日期") >= 0)
                                                    {

                                                        Lawinputdto.posting_date = todate(value); //= "2017年11月04日"  发布

                                                    }
                                                    else if (name.IndexOf("文号") >= 0)
                                                    {
                                                        Lawinputdto.document_number = value; //= 文号   中华人民共和国主席令第四十五号， "主席令第80号"

                                                    }
                                                    else if (name.IndexOf("效力等级") >= 0)
                                                    {
                                                        Lawinputdto.eff_level = new List<string>(); //= 效力等级 法律
                                                        Laweff_level ls = _baseDatasHelper.GetLaweff_level().Where(m => m.name == value).FirstOrDefault();
                                                        string strtext = string.Empty;
                                                        if (ls != null)
                                                        {
                                                            strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                            Lawinputdto.eff_level.Add(strtext);
                                                            if (ls.pid != "A")
                                                            {
                                                                if (ls.parentLaweff_level != null)
                                                                {
                                                                    strtext = ls.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.name : ls.parentLaweff_level.name + "-" + ls.parentLaweff_level.Id;
                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                    if (ls.parentLaweff_level.pid != "A")
                                                                    {
                                                                        if (ls.parentLaweff_level.parentLaweff_level != null)
                                                                        {
                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.Id;
                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                            if (ls.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                            {
                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                {
                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                    if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                    {
                                                                                        if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                        {
                                                                                            strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                            Lawinputdto.eff_level.Add(strtext);
                                                                                            if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.pid != "A")
                                                                                            {
                                                                                                if (ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level != null)
                                                                                                {
                                                                                                    strtext = ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name.Contains("-") ? ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name : ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.name + "-" + ls.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.parentLaweff_level.Id;
                                                                                                    Lawinputdto.eff_level.Add(strtext);
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }

                                                                                }
                                                                            }

                                                                        }
                                                                    }

                                                                }
                                                            }

                                                        }

                                                    }
                                                    else if (name.IndexOf("时效性") >= 0)
                                                    {
                                                        Lawinputdto.time_limited = value; //= 现行有效  失效   已被修改 尚未生效 部分失效  实际失效 

                                                    }
                                                    else if (name.IndexOf("分类") >= 0)
                                                    {
                                                        var lawtypes = value.Replace(" ", "").Replace(emm, "").Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); //= 制定机关  全国人民代表大会;
                                                        Lawinputdto.lawtype = new List<string>();
                                                        string strtext = string.Empty;
                                                        foreach (var au in lawtypes)
                                                        {
                                                            LawType ls = _baseDatasHelper.GetLawType().Where(m => m.name == au).FirstOrDefault();
                                                            if (ls != null)
                                                            {
                                                                strtext = ls.name.Contains("-") ? ls.name : ls.name + "-" + ls.Id;
                                                                Lawinputdto.lawtype.Add(strtext);
                                                                if (ls.pid == "A")
                                                                {
                                                                    continue;
                                                                }
                                                                if (ls.parentLawType != null)
                                                                {
                                                                    strtext = ls.parentLawType.name.Contains("-") ? ls.parentLawType.name : ls.parentLawType.name + "-" + ls.parentLawType.Id;
                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                    if (ls.parentLawType.pid == "A")
                                                                    {
                                                                        continue;
                                                                    }
                                                                    if (ls.parentLawType.parentLawType != null)
                                                                    {
                                                                        strtext = ls.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.Id;
                                                                        Lawinputdto.lawtype.Add(strtext);
                                                                        if (ls.parentLawType.parentLawType.pid == "A")
                                                                        {
                                                                            continue;
                                                                        }
                                                                        if (ls.parentLawType.parentLawType.parentLawType != null)
                                                                        {
                                                                            strtext = ls.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.Id;
                                                                            Lawinputdto.lawtype.Add(strtext);
                                                                            if (ls.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                            {
                                                                                continue;
                                                                            }
                                                                            if (ls.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                            {
                                                                                strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                Lawinputdto.lawtype.Add(strtext);
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.pid == "A")
                                                                                {
                                                                                    continue;
                                                                                }
                                                                                if (ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType != null)
                                                                                {
                                                                                    strtext = ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name.Contains("-") ? ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name : ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.name + "-" + ls.parentLawType.parentLawType.parentLawType.parentLawType.parentLawType.Id;
                                                                                    Lawinputdto.lawtype.Add(strtext);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        throw new Exception("简介名称不包含");
                                                    }
                                                }
                                            }
                                        }
                                        if (((HtmlSelectable)div).Node.Attributes["class"].Value.IndexOf("timeMod") >= 0)
                                        {
                                            var Listorys = div.SelectList(Selectors.XPath("//div")).ToList();
                                            historyDTO hi = new historyDTO();

                                            foreach (var div2 in Listorys.ToList())
                                            {
                                                var tmm = ((DotnetSpider.Selector.HtmlSelectable)div2).Node.Attributes["class"];
                                                if (tmm != null && tmm.Value.IndexOf("time-t1") >= 0)
                                                {
                                                    hi.effective_date = todate(div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", ""));
                                                }
                                                if (tmm != null && tmm.Value.IndexOf("time-t3") >= 0)
                                                {
                                                    hi.name = div2?.Value.ToLower().Replace(" ", "").Replace(emm, "").Replace("\r", "").Replace("\n", "");

                                                    var a = div2.Select(Selectors.XPath("//a"));
                                                    string href = ((HtmlSelectable)a).Node.Attributes["href"].Value;
                                                    hi.id = href.Substring(href.IndexOf("(\"") + 2, href.Length - href.IndexOf("\",") + 1);
                                                }

                                            }
                                            Lawinputdto.historys.Add(hi);
                                        }
                                    }
                                }


                                Lawinputdto.alias_titles = new List<string>();
                                string ttt = Lawinputdto.name.Replace("(", "（").Replace(")", "）");
                                Lawinputdto.alias_titles.Add(ttt);


                                MatchCollection mctname = Regex.Matches(ttt, "《.{1,}?》");  //有问题
                                for (int j = 0; j < mctname.Count; j++)
                                {
                                    string Alianame = mctname[j].Groups[0].Value;
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                if (ttt.IndexOf("——") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("——") + 2, ttt.Length - ttt.IndexOf("——") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }
                                if (ttt.IndexOf("－－") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("－－") + 2, ttt.Length - ttt.IndexOf("－－") - 2);
                                    Lawinputdto.alias_titles.Add(Alianame);

                                }

                                if (ttt.IndexOf("中华人民共和国") >= 0)
                                {
                                    string Alianame = ttt.Substring(ttt.IndexOf("中华人民共和国") + 7, ttt.Length - ttt.IndexOf("中华人民共和国") - 7);
                                    Lawinputdto.alias_titles.Add(Alianame);
                                }

                                //var ad = Selectable.Select(Selectors.XPath("//div[@class='ml-list js_ml-list']"));
                                //Lawinputdto.navcontent = ad.Value;


                                LawInputDetailDTO Lawdetailinputdto = new LawInputDetailDTO();
                                Lawdetailinputdto.name = Lawinputdto.name;
                                Lawdetailinputdto.alias_titles = Lawinputdto.alias_titles;
                                Lawdetailinputdto.pid = Lawinputdto.Id;
                                Lawdetailinputdto.effective_date = Lawinputdto.effective_date;
                                var content = Selectable.Select(Selectors.XPath("//div[@class='box fulltext']"));
                                Lawdetailinputdto.tiao = "0"; //": "第一百一十五条",
                                Lawdetailinputdto.text = ((HtmlSelectable)content).OuterHtml; //": "ffff"
                                Lawdetailinputdto.outerHtml = ((HtmlSelectable)content).OuterHtml; //": "ffff"
                                Lawdetailinputdto.order = "0";
                                Lawdetailinputdto.tiaoint = "0";
                                Lawdetailinputdto.Id = Lawdetailinputdto.pid + "-" + Lawdetailinputdto.order;
                                Lawinputdetaildtos.Add(Lawdetailinputdto);

                            }
                            Lawinputdtos.Add(Lawinputdto);
                            if (Lawinputdetaildtos.Count == 0)
                            {
                                string a = "";
                            }
                            _abpElasticSearch.BulkAddorUpdateAsync<LawInputDetailDTO, string>("lawdetail", Lawinputdetaildtos);

                        }

                        //var entitys = ObjectMapper.Map<List<LawInputDTO>>(ld);
                        _abpElasticSearch.BulkAddorUpdateAsync<LawInputDTO, string>("law", Lawinputdtos);
                        foreach (var item in lawrecords)
                        {
                            _lawrecordrepository.GetDbContext().Database.ExecuteSqlRaw("update LawRecord set Indexed = "+ indexNum.ToString() + ",Name='"+ Lawinputdto.name + "', Effective_date = '" + Lawinputdto.effective_date + "', Time_limited = '" + Lawinputdto.time_limited + "' where Id='" + item.Id + "'");
                        }

                        uowHandle.Complete();
                    }

                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message + "，" + ex.StackTrace + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                    Logger.Warn(ex.Message + "，" + ex.StackTrace + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"));
                }
            }

        }



        public async Task LawDeleteAsync(string id)
        {
            List<LawInputDTO> Lawinputdtos = new List<LawInputDTO>();
            LawInputDTO lawrecord = new LawInputDTO();
            lawrecord.Id = id;
            Lawinputdtos.Add(lawrecord);
            _abpElasticSearch.BulkDeleteAsync<LawInputDTO, string>("law", Lawinputdtos);
            List<LawInputDetailDTO> Lawinputdetaildtos = new List<LawInputDetailDTO>();



            LawDetailSearchInDTO detailinput = new LawDetailSearchInDTO();
            detailinput.pid = new List<string>();
            detailinput.pid.Add(id);
            detailinput.ishilhlit = 1;
            List<LawDetailSearchOutDTO> LawDetailSearchOutDTOs = await LawDetailSearchAsync(detailinput);
            _abpElasticSearch.BulkDeleteAsync<LawDetailSearchOutDTO, string>("lawdetail", LawDetailSearchOutDTOs);
            
        }


        public async Task<List<LawDetailSearchOutDTO>> LawDetailSearchAsync(LawDetailSearchInDTO input)
        {

            var request = new SearchRequest("lawdetail")
            {
                From = 0,
                Size = 9999,
                Source = new SourceFilter()
                {
                    Includes = new string[] { "id", "name", "tiaoint", "tiao", "order", "outerHtml", "effective_date", "lawdetailotherinputdtos" }
                },
            };


            QueryContainer querycontainer = null;
            
            if (input.pid != null && input.pid.Count > 0)
            {
                querycontainer = new QueryContainer();
                QueryContainer qc = new QueryContainer();
                foreach (var item in input.pid)
                {
                    qc = qc || new TermQuery
                    {
                        Field = new Field("pid"),
                        Value = item.Replace(" ", "")
                    };
                }
                querycontainer = querycontainer && (qc);
            }
            else
            {
                return null;
            }
            
            if (querycontainer != null)
            {
                request.Query = querycontainer;
            }
            var his = await _abpElasticSearch.SearchAsync<LawDetailSearchOutDTO, string>(request);
            List<LawDetailSearchOutDTO> lawdetailsearchoutdtos = new List<LawDetailSearchOutDTO>();

            foreach (var item in his.Hits)
            {
                LawDetailSearchOutDTO enty = (LawDetailSearchOutDTO)item.Source;
               
                lawdetailsearchoutdtos.Add(enty);
            }

            return lawdetailsearchoutdtos;

        }


        #region helper
        public DateTime? todate(object o)
        {
            try
            {
                if (o == null)
                {
                    return null;
                }
                else
                {
                    return Convert.ToDateTime(o.ToString().Replace("年", "-").Replace("月", "-").Replace("日", ""));
                }
            }
            catch (Exception ex)
            {
                return null;
            }

        }
        public string tostring(object o)
        {
            try
            {
                if (o == null)
                {
                    return "";
                }
                else
                {
                    return o.ToString();
                }
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public int toint(object o)
        {
            try
            {
                if (o == null)
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        public bool tobool(object o)
        {
            try
            {
                if (o == null)
                {
                    return false;
                }
                else
                {
                    return Convert.ToBoolean(o);
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        #endregion
     

       
       
    }


  
}